//
//  HWBookIntroductionCell.m
//  嗨文
//
//  Created by 响当当 on 2019/3/13.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWBookIntroductionCell.h"

@interface HWBookIntroductionCell()
@property (nonatomic, strong)UILabel *introduceLabel;//简介
@property (nonatomic, strong)UIButton *openBtn;//打开

@property (nonatomic, assign)NSInteger num;//判断打开还是关闭

@end

@implementation HWBookIntroductionCell

- (UILabel *)introduceLabel
{
    if (!_introduceLabel)
    {
        _introduceLabel = [HWUtilties creatLabelWithFrame:CGRectMake(16*kUIScaleBasePlus,17*kUIScaleBasePlus,344*kUIScaleBasePlus,52*kUIScaleBasePlus)
                                             textAligment:NSTextAlignmentLeft
                                                 textClor:LCHexColor(0x555555)
                                                 textFont:13*kUIScaleBasePlus];
        _introduceLabel.numberOfLines = 0;
    }
    return _introduceLabel;
}

- (UIButton *)openBtn
{
    if (!_openBtn)
    {
        _openBtn = [HWUtilties creatButtonWithFrame:CGRectMake(355*kUIScaleBasePlus,60*kUIScaleBasePlus,14*kUIScaleBasePlus,16*kUIScaleBasePlus)
                                       textAligment:NSTextAlignmentLeft
                                               text:nil
                                           textClor:[UIColor clearColor]
                                          buttonBGC:[UIColor clearColor]
                                           textFont:0
                                             target:self
                                             method:@selector(openIntroduce)];
        [_openBtn setImage:[UIImage imageNamed:@"arrow_bottom"] forState:UIControlStateNormal];
    }
    return _openBtn;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self.contentView addSubview:self.introduceLabel];
        [self.contentView addSubview:self.openBtn];
    }
    return self;
}


#pragma mark - 获取数据

- (CGFloat)getBackHeight:(NSString *)str
{
    self.introduceLabel.text = str;
    [self.introduceLabel sizeToFit];
    
    return 17*2*kUIScaleBasePlus + self.introduceLabel.frame.size.height;
    
}

- (void)getIntroduce:(NSDictionary *)dic andNum:(NSInteger)num
{
    
    
    if (num == 0)
    {
        [self.introduceLabel setHeight:52*kUIScaleBasePlus];
        self.introduceLabel.text = dic[@"introduce"];
        [self.openBtn setY:60*kUIScaleBasePlus];
        [self.openBtn setImage:[UIImage imageNamed:@"arrow_bottom"] forState:UIControlStateNormal];
    }
    else
    {
        self.introduceLabel.text = dic[@"introduce"];
        [self.introduceLabel sizeToFit];
        [self.openBtn setY:CGRectGetMaxY(self.introduceLabel.frame)-10*kUIScaleBasePlus];
        [self.openBtn setImage:[UIImage imageNamed:@"arrow_top"] forState:UIControlStateNormal];
    }
    
    self.num = num;

}

- (void)openIntroduce
{
    if (self.num == 0)
    {
        self.num = 1;
    }
    else
    {
        self.num = 0;
    }
    
    if (self.openIntroduceBlock)
    {
        self.openIntroduceBlock(self.num);
    }
}
@end
